import api from './index'

export const userAPI = {
  // 用户管理
  getUsers(params) {
    return api.get('/user-management/users/', { params })
  },

  createUser(data) {
    return api.post('/user-management/users/', data)
  },

  updateUser(id, data) {
    return api.put(`/user-management/users/${id}/`, data)
  },

  deleteUser(id) {
    return api.delete(`/user-management/users/${id}/`)
  },

  batchDeleteUsers(userIds) {
    return api.post('/user-management/users/batch_delete/', { user_ids: userIds })
  },

  resetPassword(id, newPassword) {
    return api.post(`/user-management/users/${id}/reset_password/`, { new_password: newPassword })
  },

  toggleUserStatus(id) {
    return api.post(`/user-management/users/${id}/toggle_status/`)
  },

  getUserPermissions(id) {
    return api.get(`/user-management/users/${id}/permissions/`)
  },

  getUserPermissionsDetail(id) {
    return api.get(`/user-management/users/${id}/permissions_detail/`)
  },

  getUserMenusDetail(id) {
    return api.get(`/user-management/users/${id}/menus_detail/`)
  },

  // 用户组管理
  getUserGroups() {
    return api.get('/user-management/user-groups/')
  },

  createUserGroup(data) {
    return api.post('/user-management/user-groups/', data)
  },

  updateUserGroup(id, data) {
    return api.put(`/user-management/user-groups/${id}/`, data)
  },

  deleteUserGroup(id) {
    return api.delete(`/user-management/user-groups/${id}/`)
  },

  getUserGroupUsers(id) {
    return api.get(`/user-management/user-groups/${id}/users/`)
  },

  // 角色管理
  getRoles() {
    return api.get('/user-management/roles/')
  },

  createRole(data) {
    return api.post('/user-management/roles/', data)
  },

  updateRole(id, data) {
    return api.put(`/user-management/roles/${id}/`, data)
  },

  deleteRole(id) {
    return api.delete(`/user-management/roles/${id}/`)
  },

  getRolePermissions(id) {
    return api.get(`/user-management/roles/${id}/permissions/`)
  },

  assignPermissions(id, permissions) {
    return api.post(`/user-management/roles/${id}/assign_permissions/`, { permissions })
  },

  // 权限管理
  getPermissions() {
    return api.get('/user-management/permissions/')
  },

  createPermission(data) {
    return api.post('/user-management/permissions/', data)
  },

  updatePermission(id, data) {
    return api.put(`/user-management/permissions/${id}/`, data)
  },

  deletePermission(id) {
    return api.delete(`/user-management/permissions/${id}/`)
  },

  // 菜单管理
  getMenus() {
    return api.get('/user-management/menus/')
  },

  getMenuTree() {
    return api.get('/user-management/menus/tree/')
  },

  createMenu(data) {
    return api.post('/user-management/menus/', data)
  },

  updateMenu(id, data) {
    return api.put(`/user-management/menus/${id}/`, data)
  },

  deleteMenu(id) {
    return api.delete(`/user-management/menus/${id}/`)
  },

  getMenuPermissions(id) {
    return api.get(`/user-management/menus/${id}/permissions/`)
  },

  // 登录历史
  getLoginHistory(params) {
    return api.get('/user-management/login-history/', { params })
  }
}
